<?php
namespace App\Api\Controllers;
use Common\ApiController;
use Common\Common;
use Common\Models\Footprints;

class FootprintController extends ApiController
{
	public function initialize()
	{
		parent::initialize();
	}

    /**
     * 添加足迹 添加到商品详情页面(此页面没用)
     */
    public function add_footprintAction(){
        $data['site'] = $this->params['site'];
        $data['image'] = $this->params['image'];
        $data['title'] = $this->params['title'];
        $data['price'] = $this->params['price'];
        $data['user_id'] = $this->user_info['id'];
        $collects = new Footprints();
        $result = $collects->footprint_save($data);
        if($result){
            $this->ok([]);
        }else{
            $this->fail(-1,'操作失败');
        }
    }

    /**
     * 删除足迹
     */
    public function unfootprintAction(){
        $collects = new Footprints();
        if(!isset($this->params['id']) || empty($this->params['id'])){
            $this->fail(-1,'收藏ids不能为空');
        }
        $result = $collects->del_footprint($this->params['id']);
        if($result){
            $this->ok([]);
        }else{
            $this->fail(-1,'操作失败');
        }
    }



    /**
     * 清空足迹
     */
    public function clearfootprintAction(){
        $collects = new Footprints();
        $result = $collects->cleardel_footprint($this->user_info['id']);
        if($result){
            $this->ok([]);
        }else{
            $this->fail(-1,'操作失败');
        }
    }


    /**
     * 列表
     */
    public function footprint_listAction(){
        //当前页数
        if(!isset($this->params['page']) || empty($this->params['page'])){
            $this->params['page'] = Common::PAGE;
        }
        //当前条数
        if(!isset($this->params['page_size']) || empty($this->params['page_size'])){
            $this->params['page_size'] = Common::PAGESIZE;
        }
        $model = new Footprints();
        $list = $model->getList($this->params);
        $this->ok($list);
    }
}
